/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2022-03-18     desktop       the first version
 */
#ifndef ALL_CODE_ALL_CODE_H_
#define ALL_CODE_ALL_CODE_H_

#include <rtthread.h>
#include <rtdevice.h>
#include <board.h>

/*  数据宏定义区域   */

#define LINE_LEN 19 //规定协议数据长度
#define frequency   100000  //  设置pwm频率为10K
#define hand_frequency   20000000  //  设置舵机频率为50HZ

/*  设备名称区   */

#define BLE_UART_NAME "uart4"   //蓝牙设备名称

/* PWM 设 备 名 称 */
#define PWM_FOOT_NAME_1 "pwm3"
#define PWM_DEV_CHANNEL_1 2 /* PWM通 道 */

//下面这两个暂时没用。
#define PWM_FOOT_NAME_2 "pwm3"
#define PWM_DEV_CHANNEL_2 4 /* PWM通 道 */

#define PWM_HAND_NAME_1 "pwm3"
#define PWM_DEV_CHANNEL_3 6 /* PWM通 道 */

/* 定 时 器 名 称 */
#define FOOT_HWTIMER_DEV_NAME "timer5"
#define HAND_HWTIMER_DEV_NAME "timer15"

/*  PIN设备-relay   */
#define Relay_PIN GET_PIN(B, 6)

/*  设备句柄区   */
extern rt_device_t ble_uart_device;
extern struct rt_device_pwm *foot_pwm_dev_1; /* PWM设 备 句 柄 */
extern struct rt_device_pwm *foot_pwm_dev_2; /* PWM设 备 句 柄 */
extern struct rt_device_pwm *hand_pwm_dev_1; /* PWM设 备 句 柄 */

extern rt_device_t foot_hw_time_dev; /* 定 时 器 设 备 句 柄 */
extern rt_device_t hand_hw_time_dev; /* 定 时 器 设 备 句 柄 */



/*  信号量区   */

/* 手部调度信号量 */
extern struct rt_semaphore hand_sch_semaphore;
/* 脚部调度信号量 */
extern struct rt_semaphore foot_sch_semaphore;
/* 手心调度信号量 */
extern struct rt_semaphore palm_sch_semaphore;
/*  线程控制块   */



/*  缓存变量区   */

/* 中断数据接收数组 */
extern rt_uint8_t temp_buff[LINE_LEN];//主机用于接收数据的BUFF
/*校验数据缓冲*/
extern rt_uint8_t temp_data[7];

extern rt_hwtimer_mode_t mode; /* 定 时 器 模 式 */
extern rt_uint32_t freq; /* 计 数 频 率 */
extern rt_hwtimerval_t foot_timeout_s; /* 定 时 器 超 时 值 */
extern rt_hwtimerval_t hand_timeout_s; /* 定 时 器 超 时 值 */
extern rt_uint8_t foot_scheduling_flag;
extern rt_uint8_t hand_scheduling_flag;
extern rt_uint32_t HAND_PWM_MAX;
extern rt_uint32_t HAND_PWM_MIN;




/*  全局函数接口声明区   */

extern void uart_device_init(void);
extern void pwm_device_init(void);
extern void pin_device_init(void);
extern void time_device_init(void);


extern rt_uint32_t get_foot_pwm_pulse(rt_uint8_t speed);
extern void pwm_foot_set(rt_uint32_t pwm1,rt_uint32_t pwm2);

extern void get_hand_pwm_pulse(rt_uint8_t angle);
extern void pwm_hand_set(rt_uint32_t pwm1);

extern void foot_app_creative(void);
extern void hand_app_creative(void);
extern void palm_app_creative(void);

#endif /* ALL_CODE_ALL_CODE_H_ */
